package com.cc2019.buke.type.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.cc2019.buke.R;
import com.cc2019.buke.type.entry.TypeW;

import java.util.List;

public class WaiguoTypeAdapter extends RecyclerView.Adapter {
    List<TypeW> typew_list;
    Context context;

    public WaiguoTypeAdapter(List<TypeW> typew_list, Context context) {
        this.typew_list = typew_list;
        this.context = context;
    }

    class TypeWHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView nameView;

        public TypeWHolder(@NonNull View itemView) {
            super(itemView);
            imageView=itemView.findViewById(R.id.typew_img);
            nameView=itemView.findViewById(R.id.typew_name);
        }
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.type_w_layout,parent,false);
        WaiguoTypeAdapter.TypeWHolder typeWHolder = new WaiguoTypeAdapter.TypeWHolder(view);
        return typeWHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        TypeW typeW=typew_list.get(position);
        WaiguoTypeAdapter.TypeWHolder typewHolder=(TypeWHolder) holder;
        typewHolder.imageView.setImageResource(typeW.getImg());
        typewHolder.nameView.setText(typeW.getName());
    }

    @Override
    public int getItemCount() {
        return typew_list.size();
    }
}
